<%@page import="javax.management.Query"%>
<%@page import="GUI.LanguageLoader"%>
<%@page import="Interface.Entity"%>
<%@page import="session.SessionInterface"%>
<%@page import="GUI.EntityGUI"%>
<%
            String name = request.getParameter("entity");
            LanguageLoader language = new LanguageLoader();
            String pk;
            EntityGUI entity;
            if (null != session.getAttribute("username")) {
                entity = new EntityGUI(name, session.getAttribute("username").toString(), session.getAttribute("gruppo").toString());
            } else {
                entity = new EntityGUI(name);
            }
            Entity listaEntity[];
            SessionInterface sessione = new SessionInterface();
            String attributeName[] = entity.getAllNameAttribute();
            pk = entity.getPrymaryKeyName();
%>

<h1><%= name%></h1>
<table class="table" cellspacing="0">
    <tr class="tableTitle">
        <%
                    for (int i = 0; i < attributeName.length; i++) {
        %>
        <td><%= language.getCaption(name, attributeName[i])%></td>
        <%
                    }
                    String Arguments[];
                    Arguments = new String[2];

                    if (request.getParameter("find") == null) {
                        Arguments[0] = "allIstance";
                    } else {
                        String query = request.getParameter("find");
                        Arguments[0] = "find";
                        for (int i = 0; i < attributeName.length; i++) {
                            entity.setAttributeValueForFind(attributeName[i], query);
                        }
                    }
                    listaEntity = sessione.find(entity, Arguments);
        %>
    </tr>
    <%
                String s;
                for (int i = 0; i < listaEntity.length; i++) {
    %> <tr> <%
                        for (int j = 0; j < attributeName.length; j++) {
                            s = listaEntity[i].getAttributeValue(attributeName[j]).toString();
                            if (!pk.equals(attributeName[j])) {
        %>
        <td><%= s%></td>
        <%
                                    } else {
        %>
        <td><a href="?GUI=viewOne&entity=<%= name%>&id=<%= s%>"><%= s%></a></td>
        <%
                                }
                            }
        %> </tr> <%
                    }
        %>

</table>